# coding=utf-8
import uuid
from django.db import models

# Create your models here.


class PictureIdentifier(models.Model):
    id = models.UUIDField("编号", primary_key=True, default=uuid.uuid4, editable=False)
    # TODO 自动生成图片归属编号

    class Meta:
        verbose_name = "图片归属"
        verbose_name_plural = "图片归属"


class Picture(models.Model):
    id = models.UUIDField("编号", primary_key=True, default=uuid.uuid4, editable=False)
    identifier = models.ForeignKey("PictureIdentifier", models.CASCADE)
    storename = models.CharField("存储名称", max_length=50, null=False, blank=False)
    size = models.IntegerField("大小", null=False)
    width = models.IntegerField("宽度", null=False)
    height = models.IntegerField("高度", null=False)
    hash = models.CharField("删除编号", max_length=50, null=False)
    delete = models.URLField("删除链接", max_length=100, null=False)
    url = models.URLField("访问链接", null=False, blank=False)

    def __str__(self):
        return "[{0:s}]({1}, {2})".format(self.storename, self.width, self.height)

    class Meta:
        verbose_name = "图片"
        verbose_name_plural = "图片"
